package codingforgreat.class01;

import java.io.File;
import java.util.LinkedList;
import java.util.Queue;

public class Class02_CountFiles {
    public static int getFileNumber(String folderPath) {
        File root = new File(folderPath);
        if(!root.isDirectory() && !root.isFile()){
            return 0;
        }
        if(root.isFile()){
            return 1;
        }
        int count = 0;
        Queue<File> queue = new LinkedList();
        queue.add(root);
        while (!queue.isEmpty()){
            File cur = queue.poll();
            for (File file : cur.listFiles()) {
                if(file.isDirectory()) {
                    queue.add(file);
                }
                if(file.isFile()){
                    count++;
                }
            }
        }
        return count;
    }
    public static void main(String[] args) {
        // 你可以自己更改目录
        String path = "F:\\workspace";
        System.out.println(getFileNumber(path));
    }
}
